#include <cstdio>
#include <algorithm>

using namespace std;

struct Node
{
    int a, b;
};

bool operator < ( const Node &a, const Node &b )
{
    return a.a < b.a;
}

Node a[ 100001 ];

int main( )
{
    int i, k, t, n, maxb[ 100001 ], mins;
    scanf("%d", &t);
    for ( k = 1; k <= t; k++ )
    {
        scanf("%d", &n);
        for ( i = 0; i < n; i++ )
            scanf("%d%d", &a[ i ].a, &a[ i ].b);
        sort( a, a + n );
        maxb[ n ] = 0;
        for ( i = n - 1; i >= 0; i-- )
            if ( maxb[ i + 1 ] < a[ i ].b )
                maxb[ i ] = a[ i ].b;
            else
                maxb[ i ] = maxb[ i + 1 ];
        mins = 0x7fffffff;
        for ( i = 0; i < n; i++ )
            if ( mins > maxb[ i + 1 ] + a[ i ].a )
                mins = maxb[ i + 1 ] + a[ i ].a;
        printf("Case %d: %d\n", k, mins);
    }
    return 0;
}
